const defaultState = {
    inputValue: 'Write Something',
    list: [
        '早8点开晨会，分配今天的开发工作',
        '早9点和项目经理作开发需求讨论会',
        '晚5:30对今日代码进行review'
    ]
}

import * as actionTypes from './actionTypes'

export default (state = defaultState, action) => {
    // console.log(state,action)
    if(action.type === actionTypes.CHANGE_INPUT){
        let newState = JSON.parse(JSON.stringify(state)) //深度拷贝state
        newState.inputValue = action.value
        return newState
    }
    if(action.type===actionTypes.ADD_ITEM){
        let newState = JSON.parse(JSON.stringify(state)) //深度拷贝state
        newState.list.push(newState.inputValue)
        newState.inputValue=""
        return newState
    }
    if(action.type===actionTypes.DELETE_ITEM){
        let newState = JSON.parse(JSON.stringify(state)) //深度拷贝state
        newState.list.splice(action.index,1)
        return newState
    }
    return state
    
    
}